/* author: Rainboy email: rainboylvx@qq.com  time: 2022年 07月 13日 星期三 19:46:51 CST */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e6+5,maxe = 1e6+5; //点与边的数量

int n,m;
/* 定义全局变量 */

struct ip_type {
    int ip[5];
};

bool operator== (ip_type &a ,ip_type &b ){
    for(int i=0;i<=4;++i){
        if(a.ip[i] != b.ip[i])
            return 0;
    }
    return 1;
}

bool mycpy (ip_type &a ,ip_type &b ){
    for(int i=0;i<=4;++i){
        if(a.ip[i] != b.ip[i])
            return 0;
    }
    return 1;
}

std::vector<ip_type> server;
std::vector<int> server_id;

bool parse(string &ip,ip_type & _ip) {
    string num="";
    int idx = 0;
    int dot_cnt =0,mao_cnt=0;
    for(int i=0;i<ip.length();++i){
        char c = ip[i];
        if(c == '.' || c == ':') {
            if( c == '.') dot_cnt++;
            else {
                mao_cnt++;
                if( dot_cnt != 3) 
                    return 0;
            }
            if( num.length() > 5 || num.length() == 0)
                return 0;
            if( num.length() > 1 && num[0] == '0')
                return 0;
            int _num = std::stoi(num);
            if( _num > 255)
                return 0;
            _ip.ip[idx++] = _num;
            //num.clear();
            num = "";
        }
        else
            num += c;
    }
    if( dot_cnt != 3 || mao_cnt != 1)
        return 0;
    if( num.length() == 0 || num.length() > 5)
        return 0;
    if( num.length() > 1 && num[0] == '0')
        return 0;
    int _num = std::stoi(num);
    if( _num > 65535)
        return 0;
    _ip.ip[idx++] = _num;
    return 1;
}

int main(int argc,char * argv[]){
    std::cin >> n;
    std::string type;
    std::string ip;
    for(int i=1;i<=n;++i){
        cin >> type  >> ip;
        ip_type myip;
        if( parse(ip, myip) ) {
            if( type[0] == 'C'){
                int id  = -1;
                for(int j=0 ;j < server.size();j++){
                    if( myip == server[j]){
                        id = j;
                        break;
                    }
                }
                if( id != -1)
                    std::cout << server_id[id] << std::endl;
                else
                    std::cout << "FAIL" << std::endl;
            }
            else {
                bool succ = 1;
                for(int j=0 ;j < server.size();j++){
                    if( server[j] == myip){
                        succ = 0;
                        break;
                    }
                }
                if( !succ ){
                    std::cout << "FAIL" << std::endl;
                }
                else {
                    std::cout << "OK" << std::endl;
                }
                server.push_back(myip);
                server_id.push_back(i);

            }
            //std::cout << "yes" << std::endl;
            //for(int j=0;j<=4;++j){
                //std::cout << myip.ip[j] << " ";
            //}
            //std::cout  << std::endl;
        }
        else {
            std::cout << "ERR" << std::endl;
        }
            //std::cout << "failed" << std::endl;

    }
    return 0;
}
